#ifndef TICKET_H
#define TICKET_H

#include "ticketinterface.h"

#include <QtCore/QDateTime>
#include <QtCore/QVariant>

class TicketEditor;
class TicketAction;
class TicketChangeset;

class Ticket : public QObject
{
    Q_OBJECT
public:
    virtual ~Ticket() {}

    virtual int id() const = 0;

    virtual void refresh() = 0;

    virtual QDateTime created() const = 0;
    virtual QDateTime modified() const = 0;

    virtual QVariant fieldByName(const QString &fieldName) const = 0;
    virtual bool containsField(const QString &fieldName) const = 0;
    virtual QStringList fieldNames() const = 0;
    virtual QVariantMap fields() const = 0;

    virtual void loadHistory() = 0;
    virtual void loadAvailableActions() = 0;

    virtual QList<TicketChangeset *> history() const = 0;
    virtual QList<TicketAction *> availableActions() const = 0;

    // Recommended usage: QScopedPointer<TicketEditor> editor(ticket.editor());
    virtual TicketEditor *editor() = 0;
    virtual Ticket *dup() = 0;

signals:
    void updated(const Ticket *ticket);
    void historyLoaded();
    void actionsLoaded();
};

QDebug operator<<(QDebug debug, const Ticket *ticket);

class TicketEditor
{
public:
    virtual ~TicketEditor() { }
    virtual void setId(int id) = 0;
    virtual void setCreated(QDateTime created) = 0;
    virtual void setModified(QDateTime modified) = 0;

    virtual void setFieldByName(const QString &fieldName, const QVariant &value) = 0;

    // Save the changes and attempt to store changes permanently
    virtual void save(const QString &comment = "") = 0;
    // Update the ticket internally
    virtual void update() = 0;
};

QDebug operator<<(QDebug debug, const TicketChangeset *changeset);

#endif // TICKET_H
